<?php
header("Content-Type:json/html;charset=utf8;");

$config = require '../config.php';

$conn = new mysqli($config['servername'], $config['username'], $config['password'], $config['dbname']);
$sql = "select  a.*,c.category from article as a,category as c where c.category = '".$_POST['keyword']."' and a.category_id = c.id or a.title like '%".$_POST['keyword']."%' and a.category_id = c.id";
$result = $conn->query($sql);
$conn->close();

$data = array();
while ($row = $result->fetch_assoc())
{
    $data[] = $row;
}
$result = ['code' =>1, 'data' => $data,  'msg' => "搜索成功!"];
print_r(json_encode($result));
